home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / programer2 / euclidlib / h / euclid < prev    next >
Text File  |  1992-04-18  |  16KB  |  550 lines

  1. /**** euclid.h ****/
  2. /* Definitions and functions to ease the use of Euclid from C.
  3.  * N.B. This module is compiled without stack checking - 
  4.  * so you can pass pointers into flex blocks to these functions
  5.  * By Paul Field
  6.  * See !ReadMe file for distribution/modification restrictions
  7.  */
  8.  
  9. #ifndef __euclid_h
  10. #define __euclid_h
  11.  
  12. #include <stdlib.h>
  13. #include "bool.h"
  14. #include "os.h"
  15.  
  16. typedef int fix6,fix8,fix14,fix16;  /* Fixpoint numbers : fixN has N binary places */
  17.  
  18. typedef enum euclid_id
  19.  { eid_plane = 0x20, eid_vane, eid_path, eid_vanepath,
  20.    eid_solid = 0x30, eid_mesh, eid_sheet,  eid_light = 0x3f,
  21.    eid_group = 0x40,
  22.    eid_transformation = 0x50, eid_matrixtransformation,
  23.    eid_colour = 0x60, eid_palette, eid_material
  24.  }euclid_id;
  25.  
  26.  
  27. /**** Partial declarations of major structures ****/
  28.  
  29. typedef struct euclid_header               euclid_header;
  30. typedef struct euclid_plane                euclid_plane;
  31. typedef struct euclid_vane                 euclid_vane;
  32. typedef struct euclid_path                 euclid_path;
  33. typedef struct euclid_vanepath             euclid_vanepath;
  34. typedef struct euclid_solid                euclid_solid;
  35. typedef struct euclid_mesh                 euclid_mesh;
  36. typedef struct euclid_sheet                euclid_sheet;
  37. typedef struct euclid_light                euclid_light;
  38. typedef struct euclid_group                euclid_group;
  39. typedef struct euclid_transformation       euclid_transformation;
  40. typedef struct euclid_matrixtransformation euclid_matrixtransformation;
  41. typedef struct euclid_colourblock          euclid_colourblock;
  42. typedef struct euclid_palette              euclid_palette;
  43. typedef struct euclid_material             euclid_material;
  44. typedef struct euclid_film                 euclid_film;
  45.  
  46.  
  47. /**** Declarations of structures ****/
  48.  
  49. typedef struct euclid_colour
  50.  { union
  51.     { unsigned int abscolour;      /* 0xXMBBGGRR - x = 8 normal,9 transparent, A blank */
  52.       euclid_colourblock *relcolour;
  53.     }c;
  54.  }euclid_colour;
  55.  
  56. typedef struct euclid_coord
  57.  { int x,y,z;
  58.  }euclid_coord;
  59.  
  60. typedef struct euclid_rotation
  61.  { fix6 x,y,z;
  62.  }euclid_rotation;
  63.  
  64. typedef struct euclid_rgb
  65.  { fix14 r,g,b;
  66.  }euclid_rgb;
  67.  
  68.  
  69. struct euclid_header
  70.  { unsigned int ecid;
  71.    unsigned int size;
  72.    unsigned int used;
  73.    void         *base;
  74.    unsigned int headersize;
  75.    euclid_coord observertrans;
  76.    fix16        zoom;
  77.    euclid_rotation  observerrot;
  78.    unsigned int     perspective;
  79.    euclid_colour    backgroundcol;
  80.    euclid_colour    edgecol;
  81.    euclid_colour    facecol;
  82.    void             *root;
  83.    euclid_palette   *palette;
  84.    euclid_material  *materials;
  85.    fix14            ambient;
  86.    void             *cache;
  87.    void             *spritearea;
  88.    fix8             flatness;
  89.  };
  90.  
  91.  
  92. typedef struct euclid_dataheader
  93.  { char           id;        /* Actually a euclid_id but must fit in 8 bits */
  94.    char           flags;
  95.    unsigned short variables;
  96.  }euclid_dataheader;
  97.  
  98.  
  99. /**** 0x20 <= Id <= 0x2f ****/
  100.  
  101. struct euclid_plane
  102.  { euclid_dataheader header;
  103.    euclid_coord      point[255];  /* Actual size of array in header.variables */
  104.  };
  105.  
  106.  
  107. struct euclid_vane
  108.  { euclid_dataheader header;
  109.    struct euclid_vanevar
  110.     { euclid_colour colour1, colour2;
  111.       euclid_coord  point;
  112.     }var[255];
  113.  };
  114.  
  115.  
  116. typedef enum euclid_pathtag
  117.  { epathtag_move = 2, epathtag_control1 = 6,
  118.    epathtag_draw = 8, epathtag_control2 = 0x106,
  119.    epathtag_end  = 0x206
  120.  }euclid_pathtag;
  121.  
  122. struct euclid_path
  123.  { euclid_dataheader header;
  124.    struct euclid_pathvar
  125.     { euclid_pathtag tag;
  126.       euclid_coord   point;
  127.     }var[255];
  128.  };
  129.  
  130.  
  131. struct euclid_vanepath
  132.  { euclid_dataheader header;
  133.    struct euclid_vanepathvar
  134.     { euclid_colour colour1, colour2;
  135.       euclid_pathtag tag;
  136.       euclid_coord   point;
  137.     }var[255];
  138.  };
  139.  
  140.  
  141.  
  142. /**** 0x30 <= Id <= 0x3f ****/
  143.  
  144. struct euclid_solid
  145.  { euclid_dataheader header;
  146.    char              name[12];
  147.    euclid_coord      boundingcentre;
  148.    unsigned int      boundingradius;
  149.    struct euclid_solidvar
  150.     { euclid_colour colour;
  151.       euclid_plane  *plane;
  152.     }var[255];
  153.  };
  154.  
  155.  
  156. typedef enum euclid_facetflag
  157.  { efacetflag_rectangles, efacetflag_nofacets,
  158.    efacetflag_triangles1, efacetflag_triangles2
  159.  }euclid_facetflag;
  160.  
  161. typedef enum euclid_meshflags
  162.  { emeshflags_facets            = 0x00,
  163.    emeshflags_cylindrical       = 0x04,
  164.    emeshflags_toroidal          = 0x08,
  165.    emeshflags_firstvane         = 0x10,
  166.    emeshflags_lastvane          = 0x20,
  167.    emeshflags_intermediatevanes = 0x40
  168.  }euclid_meshflags;
  169.  
  170. struct euclid_mesh
  171.  { euclid_dataheader header;
  172.    char              name[12];
  173.    euclid_coord      boundingcentre;
  174.    unsigned int      boundingradius;
  175.    euclid_meshflags  flags;
  176.    struct euclid_meshvar
  177.     { euclid_colour colour;
  178.       euclid_vane   *vane;
  179.     }var[255];
  180.  };
  181.  
  182.  
  183. typedef enum euclid_sheetflags
  184.  { esheetflags_nofacets   = 0x001,
  185.    esheetflags_notexture  = 0x002,
  186.    esheetflags_wraponu    = 0x004,
  187.    esheetflags_wraponv    = 0x008,
  188.    esheetflags_uis0       = 0x010,
  189.    esheetflags_uis1       = 0x020,
  190.    esheetflags_vis0       = 0x040,
  191.    esheetflags_vis1       = 0x080,
  192.    esheetflags_ureversed  = 0x100,
  193.    esheetflags_vreversed  = 0x200,
  194.    esheetflags_firstpath  = 0x300,
  195.    esheetflags_secondpath = 0x400
  196.  }euclid_sheetflags;
  197.  
  198. typedef enum euclid_blendfn
  199.  { eblendfn_cylindrical, eblendfn_sum
  200.  }euclid_blendfn;
  201.  
  202. struct euclid_sheet
  203.  { euclid_dataheader header;
  204.    char              name[12];
  205.    euclid_coord      boundingcentre;
  206.    unsigned int      boundingradius;
  207.    euclid_sheetflags flags;
  208.    euclid_blendfn    blendfn;
  209.    euclid_coord      blendaux;
  210.    euclid_colour     backgroundcol;
  211.    void              *texture;
  212.    struct euclid_sheetvar
  213.     { euclid_colour colour;
  214.       euclid_path   *path;
  215.     }var[255];
  216.  };
  217.  
  218.  
  219. typedef enum euclid_lightflags
  220.  { elightflags_off = 1, elightflags_directional = 2
  221.  }euclid_lightflags;
  222.  
  223. struct euclid_light
  224.  { euclid_dataheader header;
  225.    euclid_rgb        intensities;
  226.    euclid_lightflags flags;
  227.    int               reserved[2];   /* Must be 0 */
  228.  };
  229.  
  230.  
  231.  
  232. /**** 0x40 <= Id <= 0x4f ****/
  233.  
  234. struct euclid_group
  235.  { euclid_dataheader header;
  236.    char              name[12];
  237.    euclid_coord      boundingcentre;
  238.    unsigned int      boundingradius;
  239.    struct euclid_groupvar
  240.     { euclid_transformation *transformation;
  241.       void                  *grouporprim;
  242.     }var[255];
  243.  };
  244.  
  245.  
  246.  
  247. /**** 0x50 <= Id <= 0x5f ****/
  248.  
  249. struct euclid_transformation
  250.  { euclid_dataheader header;
  251.    euclid_coord      translation;
  252.    fix16             scale;
  253.    euclid_rotation   rotation;
  254.  };
  255.  
  256.  
  257. struct euclid_matrixtransformation
  258.  { euclid_dataheader header;
  259.    euclid_coord      translation;
  260.    fix16             scale;
  261.    fix14             matrix[3][3];
  262.  };
  263.  
  264.  
  265.  
  266. /**** 0x60 <= Id <= 0x6f ****/
  267.  
  268. struct euclid_colourblock
  269.  { euclid_dataheader header;
  270.    unsigned int      flags;  /* Should be 0 for now */
  271.    char              spritename[12];
  272.  };
  273.  
  274.  
  275. typedef enum euclid_palettetype
  276.  { epalettetype_monochrome=1, epalettetype_polychrome, epalettetype_256
  277.  }euclid_palettetype;
  278.  
  279. struct euclid_palette
  280.  { euclid_dataheader  header;
  281.    euclid_palettetype type;
  282.    unsigned int       maxintensity;
  283.    unsigned int       lines;
  284.    struct euclid_palettevar
  285.     { int dontknow[16];   /* I'm not sure what should be here */
  286.     }var[255];
  287.  };
  288.  
  289.  
  290. struct euclid_material
  291.  { euclid_dataheader header;
  292.    struct euclid_materialvar
  293.     { char  name[12];
  294.       fix14 ambient;
  295.       fix14 diffuse;
  296.       fix14 spectral;
  297.       int   shine;
  298.       int   reserved[4]; /* Must be 0 */
  299.     }var[255];
  300.  };
  301.  
  302.  
  303. /**** Definitions for Euclid Films ****/
  304.  
  305. typedef enum euclid_compression
  306.  { ecompression_runlength, ecompression_lzw  /* I think 0 is run-length - may be wrong */
  307.  }euclid_compression;
  308.  
  309. typedef enum euclid_filmflags
  310.  { efilmflags_filmtype, efilmflags_rewind = 4
  311.  } euclid_filmflags;
  312.  
  313. typedef enum euclid_filmtype
  314.  { efilmtype_normal, efilmtype_delta, efilmtype_deltafixed
  315.  }euclid_filmtype;
  316.  
  317. struct euclid_film
  318.  { unsigned int       length;
  319.    char               name[12];
  320.    unsigned int       startoffset;
  321.    unsigned int       width;
  322.    unsigned int       height;
  323.    unsigned int       mode;
  324.    euclid_compression technique;
  325.    euclid_filmflags   flags;
  326.  };
  327.  
  328.  
  329. /**** Functions ****/
  330.  
  331. /* Handy macros for converting doubles to fixed point integers and vice versa */
  332.  
  333. #define tofixN(d,n) ((int)((d)*(1<<(n))+0.5))
  334.  
  335. #define tofix6(d)  tofixN(d,6)
  336. #define tofix8(d)  tofixN(d,8)
  337. #define tofix14(d) tofixN(d,14)
  338. #define tofix16(d) tofixN(d,16)
  339.  
  340. #define fromfixN(i,n) ((double)(i)/(1<<(n)))
  341.  
  342. #define fromfix6(i)  fromfixN(i,6)
  343. #define fromfix8(i)  fromfixN(i,8)
  344. #define fromfix14(i) fromfixN(i,14)
  345. #define fromfix16(i) fromfixN(i,16)
  346.  
  347.  
  348. /* Handy functions for de/constructing absolute colours */
  349.  
  350. #define euclid_makecolour(m,r,g,b) (((m)<<24)|((b)<<16)|((g)<<8)|(r))
  351.  
  352. void euclid_getcolour(unsigned int c, unsigned int *m,
  353.                       unsigned int *r, unsigned int *g, unsigned int *b);
  354.  /* Breaks an absolute colour 'c' down into its component parts and returns
  355.   * them in 'm','r','g' and 'b'.
  356.   */
  357.  
  358.  
  359. /* Euclid uses strings that terminate with a '0d' character while C uses '0' terminated
  360.  * characters. The following two function convert between the two.
  361.  */
  362.  
  363. void euclid_setname(char *name, const char *cstring);
  364.  /* Copies 'cstring' to 'name' in the euclid data structure.
  365.   */
  366.  
  367. void euclid_getname(char *cstring, const char *name);
  368.  /* Copies 'name' (in the euclid data structure) to 'cstring'.
  369.   */
  370.  
  371.  
  372. /**** Main interface functions for euclid module ****/
  373.  
  374. typedef enum euclid_initflags
  375.  { einitflags_blackonwhite    = 1,
  376.    einitflags_perspectiveplus = 2
  377.  }euclid_initflags;
  378.  
  379. os_error *euclid_initialise(euclid_initflags flags, euclid_header *structure,
  380.                             size_t size, int *version);
  381.  /* Initialises a picture structure.
  382.   * If flags == -1 this updates the euclid module's current block pointer.
  383.   * On return 'version' contains the module version number x 100.
  384.   * You can pass NULL in 'version' if you are not interested in its value.
  385.   */
  386.  
  387.  
  388. typedef unsigned int euclid_drawstyle;  /* Can't do this with an enum, needs unsigned */
  389. #define edrawstyle_wireframe        0x00000001
  390. #define edrawstyle_mainstyle        0x00000002
  391. #define edrawstyle_monochrome       0x00000080
  392. #define edrawstyle_systemvisible    0x00000100
  393. #define edrawstyle_lightson         0x00000200
  394. #define edrawstyle_frontlighton     0x00000400
  395. #define edrawstyle_continuetimedout 0x00000800
  396. #define edrawstyle_timeout          0x00001000  /* 9 bits - timeout in centiseconds */
  397. #define edrawstyle_absolutepolygons 0x04000000
  398. #define edrawstyle_vdudrivers       0x08000000
  399. #define edrawstyle_oldpalette       0x10000000
  400. #define edrawstyle_drawfileinfo     0x20000000
  401. #define edrawstyle_vduvars          0x40000000
  402. #define edrawstyle_preprocess       0x80000000
  403.  
  404. typedef enum euclid_mainstyle
  405.  { emainstyle_facesonly, emainstyle_facesandedges, emainstyle_raytrace
  406.  }euclid_mainstyle;
  407.  
  408. typedef enum euclid_drawflags
  409.  { edraw_flags_noshadows
  410.  }euclid_drawflags;
  411.  
  412. typedef struct euclid_drawinfo
  413.  { unsigned int nexty, nextx;
  414.    unsigned int memory;
  415.    unsigned int voxels;
  416.    unsigned int pixels;
  417.    unsigned int rays;
  418.    unsigned int rayhits;
  419.    unsigned int intersectiontests;
  420.    unsigned int voxelsvisited;
  421.    unsigned int polygonswhensplit;
  422.    unsigned int polygons;
  423.    char  depth;
  424.    char  simplicity;
  425.    char  maxrecursion;
  426.    char  flags;         /* Type should be 'euclid_drawflags' but it must fit in 1 byte */
  427.    fix14 cutoff;
  428.  }euclid_drawinfo;
  429.  
  430. os_error *euclid_draw(euclid_drawstyle style, euclid_header *structure,
  431.                       int xoffset, int yoffset, const char *camera, void *vduvars,
  432.                       BOOL *timedout, euclid_drawinfo **infoblock);
  433.  /* See !Euclid.Docs.SWIs and !ArcLight.Docs.RayTrace
  434.   * (camera == NULL - no camera).
  435.   * You can pass NULL in 'timedout' and 'infoblock' if you are not interested in their
  436.   * values. Warning : if there is no timeout then '*timedout' will be undefined
  437.   * You may find it easier to use the 'edraw' module.
  438.   */
  439.  
  440.  
  441. os_error *euclid_load(BOOL postprocessonly, euclid_header *structure,
  442.                       const char *filename);
  443.  /* See Docs.SWIs
  444.   */
  445.  
  446. os_error *euclid_save(euclid_header *structure, const char *filename);
  447.  /* See Docs.SWIs
  448.   */
  449.  
  450. os_error *euclid_append(BOOL postprocess, euclid_header *structure,const char *filename);
  451.  /* See Docs.SWIs
  452.   */
  453.  
  454. os_error *euclid_find(euclid_header *structure, const char *name,
  455.                       char **leaf, euclid_transformation **transformation,
  456.                       euclid_matrixtransformation **matrix,
  457.                       euclid_matrixtransformation **inverse,
  458.                       void **entry,
  459.                       euclid_group **group);
  460.  /* See Docs.SWIs
  461.   * You can pass NULL in any of the 'output' variables if you are not interested in
  462.   * their values.
  463.   */
  464.  
  465. os_error *euclid_list(void **object, euclid_header *structure, euclid_id id);
  466.  /* Finds the next object of type 'id' starting from 'object'.
  467.   * If id==0 all types are found.
  468.   */
  469.  
  470.  
  471. /* Not much point interfacing to Euclid_Set and Euclid_Show - you can use the
  472.  * structures defined above to access the appropriate data.
  473.  *
  474.  * The same applies for Euclid_Translate, Euclid_Rotate and Euclid_Zoom.
  475.  */
  476.  
  477.  
  478. os_error *euclid_create(unsigned int children, euclid_header *structure, euclid_id id,
  479.                         void *newobject);
  480.  /* Creates an object and returns a pointer to it in 'newobject'.
  481.   * BE VERY CAREFUL. Your fourth parameter should be a pointer to a pointer e.g.
  482.   *    { euclid_mesh *mesh;
  483.   *      euclid_create(0,structure,eid_mesh,&mesh);
  484.   *    }
  485.   * For more details see Docs.SWIs
  486.   */
  487.  
  488. os_error *euclid_destroy(euclid_header *structure, void *object);
  489.  /* See Docs.SWIs
  490.   */
  491.  
  492. os_error *euclid_insert(unsigned int entry, euclid_header *structure, void *object,
  493.                         void *newentry);
  494.  /* BE VERY CAREFUL. Your fourth parameter should be a pointer to a pointer e.g.
  495.   *    { euclid_mesh *mesh;
  496.   *      euclid_insert(0,structure,object,&mesh);
  497.   *    }
  498.   * See Docs.SWIs
  499.   */
  500.  
  501. os_error *euclid_delete(unsigned int entry, euclid_header *structure, void *object);
  502.  /* See Docs.SWIs
  503.   */
  504.  
  505.  
  506. os_error *euclid_getsystemmaterials(euclid_material **materials);
  507.  /* On return, 'materials' points to the system materials table.
  508.   * This is Euclid_MiscOp 2
  509.   */
  510.  
  511. os_error *euclid_imagesmooth(int reserved_settozero);
  512.  /* Smooths the image in the current graphics window.
  513.   * This is Euclid_MiscOp 3
  514.   */
  515.  
  516. os_error *euclid_blocksize(euclid_id id, unsigned *headersize, unsigned *variablesize);
  517.  /* Returns values for the size of the fixed and variable parts of a block.
  518.   * This is Euclid_MiscOp 4
  519.   */
  520.  
  521. os_error *euclid_ditherpattern(unsigned colour, unsigned *bytes);
  522.  /* Returns in 'bytes' the byts to be used on the screen to represent 'colour'.
  523.   * (You can use 'euclid_makecolour' to create the colour value)
  524.   * This is Euclid_MiscOp 5
  525.   */
  526.  
  527. os_error *euclid_invalidatepalettecache(void);
  528.  /* Call if your application recieves a 'palette changed' message.
  529.   * This is Euclid_MiscOp 6
  530.   */
  531.  
  532. os_error *euclid_setdrawparams(char depth, char simplicity, char maxrecursion,
  533.                                euclid_drawflags, fix14 cutoff);
  534.  /* See !Arclight.Docs.Raytrace - This is Euclid_MiscOp 7
  535.   */
  536.  
  537. os_error *euclid_closedown(void);
  538.  /* See Docs.SWIs
  539.   */
  540.  
  541. os_error *euclid_compress(euclid_compression type, void **data, void **screenbase);
  542.  /* See Docs.SWIs
  543.   */
  544.  
  545. os_error *euclid_expand(euclid_compression type, void **data, void **screenbase);
  546.  /* See Docs.SWIs
  547.   */
  548.  
  549. #endif
  550.